package com.ruoyi.business.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.BusAcquisitionCard;
import com.ruoyi.business.service.IBusAcquisitionCardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据采集卡Controller
 * 
 * @author asher
 * @date 2021-10-17
 */
@RestController
@RequestMapping("/business/card")
public class BusAcquisitionCardController extends BaseController
{
    @Autowired
    private IBusAcquisitionCardService busAcquisitionCardService;

    /**
     * 查询数据采集卡列表
     */
    @PreAuthorize("@ss.hasPermi('business:card:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusAcquisitionCard busAcquisitionCard)
    {
        startPage();
        List<BusAcquisitionCard> list = busAcquisitionCardService.selectBusAcquisitionCardList(busAcquisitionCard);
        return getDataTable(list);
    }

    /**
     * 导出数据采集卡列表
     */
    @PreAuthorize("@ss.hasPermi('business:card:export')")
    @Log(title = "数据采集卡", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusAcquisitionCard busAcquisitionCard)
    {
        List<BusAcquisitionCard> list = busAcquisitionCardService.selectBusAcquisitionCardList(busAcquisitionCard);
        ExcelUtil<BusAcquisitionCard> util = new ExcelUtil<BusAcquisitionCard>(BusAcquisitionCard.class);
        return util.exportExcel(list, "数据采集卡数据");
    }

    /**
     * 获取数据采集卡详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:card:query')")
    @GetMapping(value = "/{acquisitionCardId}")
    public AjaxResult getInfo(@PathVariable("acquisitionCardId") Long acquisitionCardId)
    {
        return AjaxResult.success(busAcquisitionCardService.selectBusAcquisitionCardByAcquisitionCardId(acquisitionCardId));
    }

    /**
     * 新增数据采集卡
     */
    @PreAuthorize("@ss.hasPermi('business:card:add')")
    @Log(title = "数据采集卡", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusAcquisitionCard busAcquisitionCard)
    {
        return toAjax(busAcquisitionCardService.insertBusAcquisitionCardWithChannels(busAcquisitionCard));
    }

    /**
     * 修改数据采集卡
     */
    @PreAuthorize("@ss.hasPermi('business:card:edit')")
    @Log(title = "数据采集卡", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusAcquisitionCard busAcquisitionCard)
    {
        return toAjax(busAcquisitionCardService.updateBusAcquisitionCard(busAcquisitionCard));
    }

    /**
     * 删除数据采集卡
     */
    @PreAuthorize("@ss.hasPermi('business:card:remove')")
    @Log(title = "数据采集卡", businessType = BusinessType.DELETE)
	@DeleteMapping("/{acquisitionCardIds}")
    public AjaxResult remove(@PathVariable Long[] acquisitionCardIds)
    {
        return toAjax(busAcquisitionCardService.deleteBusAcquisitionCardByAcquisitionCardIds(acquisitionCardIds));
    }
}
